import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class EmployeeInfoDAO {
    private static final String URL = "jdbc:mysql://localhost:3306/your_database_name";
    private static final String USERNAME = "your_username";
    private static final String PASSWORD = "your_password";

    public void addEmployee(EmployeeInfo employee) {
        try (Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
             PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO employee_info (id_number, gender, mobile, email, name, salary_id) VALUES (?,?,?,?,?,?)")) {
            preparedStatement.setString(1, employee.getIdNumber());
            preparedStatement.setString(2, employee.getGender());
            preparedStatement.setString(3, employee.getMobile());
            preparedStatement.setString(4, employee.getEmail());
            preparedStatement.setString(5, employee.getName());
            preparedStatement.setInt(6, employee.getSalaryId());
            preparedStatement.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public List<EmployeeInfo> getAllEmployees() {
        List<EmployeeInfo> employees = new ArrayList<>();
        try (Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
             PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM employee_info");
             ResultSet resultSet = preparedStatement.executeQuery()) {
            while (resultSet.next()) {
                EmployeeInfo employee = new EmployeeInfo();
                employee.setEmployeeId(resultSet.getInt("employee_id"));
                employee.setIdNumber(resultSet.getString("id_number"));
                employee.setGender(resultSet.getString("gender"));
                employee.setMobile(resultSet.getString("mobile"));
                employee.setEmail(resultSet.getString("email"));
                employee.setName(resultSet.getString("name"));
                employee.setSalaryId(resultSet.getInt("salary_id"));
                employees.add(employee);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return employees;
    }
    // 其他CRUD操作方法
}